package org.jsola.hr.helper;

import org.jsola.hr.dto.NameVerifiedAddDTO;
import org.jsola.hr.dto.NameVerifiedUpdateDTO;
import org.jsola.hr.entity.NameVerifiedDO;
import org.jsola.hr.query.NameVerifiedQuery;
import org.jsola.hr.service.INameVerifiedService;
import org.jsola.hr.vo.NameVerifiedVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 实名认证
 *
 * @author zhr
 */
@Component
public class NameVerifiedTestHelper extends BaseTestHelper {
    
    @Autowired
    private INameVerifiedService nameVerifiedService;

    /**
     * 生成add测试数据
     * @return NameVerifiedAddDTO
     */
    public NameVerifiedAddDTO getNameVerifiedAddDTO(){
        NameVerifiedAddDTO nameVerifiedAddDTO = new NameVerifiedAddDTO();
        nameVerifiedAddDTO.setName(getRandomValue("varchar",50));
        nameVerifiedAddDTO.setIdCard(getRandomValue("varchar",32));
        nameVerifiedAddDTO.setPositiveUrl(getRandomValue("varchar",255));
        nameVerifiedAddDTO.setReverseUrl(getRandomValue("varchar",255));
        return nameVerifiedAddDTO;
    }

    /**
     * 生成add测试数据
     * @return NameVerifiedAddDTO
     */
    public NameVerifiedAddDTO getAddDTO(){
        NameVerifiedAddDTO nameVerifiedAddDTO = new NameVerifiedAddDTO();
        nameVerifiedAddDTO.setName("陈永磊");
        nameVerifiedAddDTO.setIdCard("371121199412194511");
        nameVerifiedAddDTO.setPositiveUrl("https://res.huaerk.com/local/8aab561a-f308-4ffe-866c-10b472225432.jpg");
        nameVerifiedAddDTO.setReverseUrl(getRandomValue("varchar",255));
        return nameVerifiedAddDTO;
    }


    /**
     * 生成update测试数据
     * @return NameVerifiedUpdateDTO
     */
    public NameVerifiedUpdateDTO getNameVerifiedUpdateDTO(NameVerifiedVO nameVerifiedVO){
        return nameVerifiedService.selectDOById(nameVerifiedVO.getId(), SITE_ID).to(NameVerifiedUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return NameVerifiedQuery
     */
    public NameVerifiedQuery getNameVerifiedQuery() {
        NameVerifiedQuery nameVerifiedQuery = new NameVerifiedQuery();
        List<NameVerifiedDO> nameVerifiedDOList = nameVerifiedService.list(new NameVerifiedDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(nameVerifiedDOList)) {
            NameVerifiedDO nameVerifiedDO = nameVerifiedDOList.get(0);
            nameVerifiedQuery = nameVerifiedDO.to(NameVerifiedQuery.class);
        }
        return nameVerifiedQuery;
    }

    /**
     * 保存示例
     * @return NameVerifiedVO
     */
    public NameVerifiedVO saveNameVerifiedExample(){
        NameVerifiedAddDTO addDTO = this.getAddDTO();
        NameVerifiedVO nameVerifiedVO = nameVerifiedService.save(addDTO,buildTokenUser());
        return nameVerifiedVO;
    }


}

